package com.app.micaihu.view.army.header

import android.content.Context
import android.content.Intent
import android.view.View
import com.app.base.BaseMvpHeaderView
import com.app.micaihu.R
import com.app.micaihu.configure.Config
import com.app.micaihu.view.army.activity.ArmyOfficialPositionListActivity
import com.app.micaihu.view.army.adapter.ArmyMemberHeaderListAdapter
import com.app.micaihu.view.army.contract.ArmyMemberContract
import com.app.micaihu.view.army.presenter.ArmyMemberPresenter
import com.app.micaihu.view.bean.ArmyMember
import com.app.micaihu.view.main.view.WrapContentLinearLayoutManager
import com.app.micaihu.view.user.userinfo.activity.MyHomepageDynamicActivity
import com.blankj.utilcode.util.ActivityUtils
import kotlinx.android.synthetic.main.army_member_header.view.*

class ArmyMemberHeader(context: Context,gid: String) : BaseMvpHeaderView<ArmyMemberContract.View, ArmyMemberPresenter>(context = context), ArmyMemberContract.View {

    override fun getLayoutId() = R.layout.army_member_header
    override fun getPresenter() = ArmyMemberPresenter(gid)
    private var gid = ""

    init {
        this.gid = gid
    }

    private val armyMemberHeaderListAdapter: ArmyMemberHeaderListAdapter by lazy {
        val armyMemberHeaderListAdapter = ArmyMemberHeaderListAdapter()
        rvMember.layoutManager = WrapContentLinearLayoutManager(context)
        armyMemberHeaderListAdapter
    }

    override fun setData() {
        rvMember.adapter = armyMemberHeaderListAdapter
    }

    override fun addListeners() {
        armyMemberHeaderListAdapter.setOnItemClickListener { adapter, view, position ->
            val item = armyMemberHeaderListAdapter.getItem(position)
            MyHomepageDynamicActivity.goToUserHomePage(ActivityUtils.getTopActivity(), item.uid)
        }
        llMemberAdmin.setOnClickListener {
            val intent = Intent(context, ArmyOfficialPositionListActivity::class.java)
            intent.putExtra(Config.Extra.id, gid)
            context.startActivity(intent)
        }
    }

    fun setList(list: List<ArmyMember.Admin>?) {
        tvTopTitle.text = "创始人、军团管理(${list?.size})人"
        armyMemberHeaderListAdapter.setNewInstance(list?.toMutableList())
    }

    fun setMemberSize(memberSize: Int) {
        tvBottomTitle.text = "军团成员(${memberSize})人"
    }

    fun setHaveDelAuthority(haveDelAuthority: Boolean) {
        if (haveDelAuthority) {
            llMemberAdmin.visibility = View.VISIBLE
        } else {
            llMemberAdmin.visibility = View.GONE
        }
    }
}